import numpy as np
import matplotlib.pyplot as plt
from math import ceil, floor, sqrt
from matplotlib import gridspec
from matplotlib import rcParams

rcParams['font.family'] = 'times new roman'
rcParams['font.size'] = 14
rcParams['font.weight'] = 'normal'

# topology
numToRs = 64
numHosts = 16
numLinks = 10
numSLinks = 2

trafficTypes = ['tor_stride']  # 'stride', 'random', 'host_stride', 'tor_stride'
schedulers = ['Detour',  'OSA', 'OvS', 'Jelly']  #'Jelly',

sum_osa = []
sum_ovs = []
sum_jelly = []
sum_detour = []

for trafficType in trafficTypes:
    for scheduler in schedulers:
        flowsFileName = "%s_%s_%sToRs_%sHosts_%sLinks.txt" \
                        % (scheduler, trafficType, numToRs, numHosts, numLinks)

        with open(flowsFileName, 'r') as f:
            for line in f.readlines():
                split = line.split()

                if scheduler == "Detour":
                    sum_detour.append(float(split[-1]))
                elif scheduler == "OvS":
                    sum_ovs.append(float(split[-1]))
                elif scheduler == "OSA":
                    sum_osa.append(float(split[-1]))
                elif scheduler == "Jelly":
                    sum_jelly.append(float(split[-1]))

print ("average bisection bandwidth")
avg_osa = sum(sum_osa)/len(sum_osa)
avg_ovs = sum(sum_ovs)/len(sum_ovs)
avg_jelly = sum(sum_jelly)/len(sum_jelly)
avg_detour = sum(sum_detour)/len(sum_detour)

print ('Detour: \t%s' % avg_detour)
print ('OSA: \t\t%s' % avg_osa)
print ('OvS: \t\t%s' % avg_ovs)
print ('Jelly: \t\t%s' % avg_jelly)

